'use strict';
const db = uniCloud.database()

exports.main = async (event, context) => {
    const { index } = event
    const collection = db.collection('todo')

    // 获取今天的开始和结束时间
    const today = new Date()
    today.setHours(0, 0, 0, 0)
    const tomorrow = new Date(today)
    tomorrow.setDate(tomorrow.getDate() + 1)

    // 查询今天的待办事项
    const res = await collection.where({
        createTime: {
            $gte: today,
            $lt: tomorrow
        },
        isOver: index === 1 ? true : false
    }).get()

    return {
        code: 0,
        data: res.data
    }
} 